# ifndef __MTATransform_H_
# define __MTATransform_H_

# include "PtAlgo.h"

//
// Parameters of multi-triangle affine transformation based on Delone' triangulation.
//

struct mta_transform_t {
	void PushPair (const point_t & _ptFrom, const point_t & _ptTo) {
		m_points.push_back (_ptFrom);
		m_FromTo.push_back (std::make_pair (_ptFrom, _ptTo));
	}

	bool Calculate ();

	void ApplyTo (point_t & _p) const;

  private:
	typedef std::pair<point_t,point_t> p2p_t;

	std::vector<p2p_t> m_FromTo;
	std::vector<point_t> m_points;
	rect_t m_rectBound;

	struct delone_tri_t {
		std::pair<point_t, point_t> p [3];
		rect_t rectBound;
		aff_transform_t at;
	};
	std::vector<delone_tri_t> m_Triangles;
	int _GetTriIndex  (const point_t & _p) const;

	struct delone_area_t {
		//      ^
		//     / v2
		//    /
		// p1/          *<<-INSIDE AREA
		//   ^
		//  v1\   
		//     \     v0
		//    p0<-------------------------
		p2p_t v [3]; // v0,v2 - bisectors of external nodes, v1 - external edge
		p2p_t p [2]; // p0,p1 - external nodes
		int tr_idx;  // index in m_Triangles
	};
	std::vector<delone_area_t> m_Areas;
	int _GetAreaIndex (const point_t & _p) const;
};

# endif // __MTATransform_H_